package cn.pupil.springframework.aop.framework;

import cn.pupil.springframework.aop.AdvisedSupport;

/**
 * @Description: 代理工厂
 * @Author: pupil
 * @Date: 2024/11/21 下午 4:52
 */
public class ProxyFactory {

    // AOP通知和通知器的包装类
    private AdvisedSupport advisedSupport;

    public ProxyFactory(AdvisedSupport advisedSupport) {
        this.advisedSupport = advisedSupport;
    }

    public Object getProxy() {
        return createAopProxy().getProxy();
    }

    /**
     * 创建Aop的代理对象
     *
     * @return
     */
    private AopProxy createAopProxy() {
        if (advisedSupport.isProxyTargetClass()) {
            return new Cglib2AopProxy(advisedSupport);
        }

        return new JdkDynamicAopProxy(advisedSupport);
    }
}
